﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Portal.Api;

namespace Portal.Modules.ContentScheduler
{
  public partial class EditPageState : Portal.StateBase.ModuleState
  {
    ContentSchedulerHandler _contentSchedulerHandler;

    protected void Page_Load(object sender, EventArgs e)
    {
      if (TransitionArgument != null)
        ViewState["TransArg"] = TransitionArgument;

      // Handler für diesen Datensatz einrichten.
      _contentSchedulerHandler = new ContentSchedulerHandler(this, new Guid(ViewState["TransArg"].ToString()));

      // Configure CKEditor
      CKEditorConfigurator Cnfg = new CKEditorConfigurator(HtmlEditor);
      Cnfg.ConfigureToolbarInplaceNoForm();
      if (!ControlPostback)
      {
        // Daten abfüllen.
        HtmlEditor.Text = _contentSchedulerHandler.GetContent();
      }
    }

    protected void OnSave(object sender, EventArgs e)
    {
      _contentSchedulerHandler.SaveContent(HtmlEditor.Text);
    }

    protected void OnCancel(object sender, EventArgs e)
    {
      ProcessEvent((int)StateEvent.Cancel);
    }

    protected void OnSaveBack(object sender, EventArgs e)
    {
      _contentSchedulerHandler.SaveContent(HtmlEditor.Text);
      ProcessEvent((int)StateEvent.Save);
    }
  }
}